home *** CD-ROM | disk | FTP | other *** search
/ AI Game Programming Wisdom / AIGameProgrammingWisdom.iso / SourceCode / 11 Learning / 04 Mommersteeg / Tennis / SoundBuffer.h < prev    next >
Encoding:
C/C++ Source or Header  |  2001-09-23  |  2.5 KB  |  73 lines

  1. //----------------------------------------------------------------------------------------------
  2. // Sequential Prediction Demo: The positioning pattern
  3. // 
  4. // Author:  Fri Mommersteeg
  5. // Date:    10-09-2001
  6. // File:    SoundBuffer.h
  7. //----------------------------------------------------------------------------------------------
  8.  
  9. #ifndef __SOUNDBUFFER_H
  10. #define __SOUNDBUFFER_H
  11.  
  12. //----------------------------------------------------------------------------------------------
  13. // Include files
  14. //----------------------------------------------------------------------------------------------
  15.  
  16. #include "DirectSound.h"
  17.  
  18. //----------------------------------------------------------------------------------------------
  19. // Defined constants
  20. //----------------------------------------------------------------------------------------------
  21.  
  22. #define WAVEVERSION         1
  23. #define ER_MEM                 0xe000
  24. #define ER_CANNOTOPEN         0xe100
  25. #define ER_NOTWAVEFILE         0xe101
  26. #define ER_CANNOTREAD         0xe102
  27. #define ER_CORRUPTWAVEFILE    0xe103
  28. #define ER_CANNOTWRITE        0xe104
  29. #define DSB_DEFAULT            0
  30.  
  31. //----------------------------------------------------------------------------------------------
  32. // CSoundBuffer: Convenient wrapper class for a DirectSound buffer
  33. //----------------------------------------------------------------------------------------------
  34.  
  35. class CSoundBuffer {
  36. public:
  37.                         CSoundBuffer();
  38.                         ~CSoundBuffer();
  39.  
  40. public:
  41.     void                Create(LPDS lpds, DWORD dwBufferSize, DWORD dwFrequency = 22050, WORD nChannels = 2, WORD wBitsPerSample = 8, DWORD dwFlags = DSB_DEFAULT);
  42.     void                CreateWave(LPDS lpds, LPSTR strWave, DWORD dwFlags = DSB_DEFAULT);
  43.     void                CreateCopy(LPDS lpds, LPDSB lpDSB);
  44.     void                CreateDuplicate(LPDS lpds, LPDSB lpDSB);
  45.  
  46.     void                Release();
  47.     void                ReleaseCopy();
  48.  
  49.     void                Play(BOOL bLooping = FALSE);
  50.     void                Stop();
  51.     void                Silence();
  52.  
  53. private:
  54.     int                    WaveOpenFile(TCHAR*, HMMIO *, WAVEFORMATEX **, MMCKINFO *);
  55.     int                    WaveStartDataRead(HMMIO *, MMCKINFO *, MMCKINFO *);
  56.     int                    WaveReadFile(HMMIO, UINT, BYTE *, MMCKINFO *, UINT *);
  57.     int                    WaveCloseReadFile(HMMIO *, WAVEFORMATEX **);
  58.     int                    WaveLoadFile(TCHAR*, UINT *, WAVEFORMATEX **, BYTE **);
  59.  
  60. private:
  61.     WAVEFORMATEX *        pwfx;              // Wave format info.
  62.     HMMIO                hmmio;            // File handle.
  63.     MMCKINFO            mmckinfo;         // Chunk info.
  64.     MMCKINFO            mmckinfoParent;   // Parent chunk info.
  65.  
  66.     LPDS                lpDS;
  67.     LPDSB                lpDSB;
  68. };
  69.  
  70. //----------------------------------------------------------------------------------------------
  71. #endif // __SOUNDBUFFER_H
  72.  
  73.